.class public abstract Lcom/sponsorpay/sdk/android/publisher/OfferWebClient;
.super Landroid/webkit/WebViewClient;
.source "OfferWebClient.java"


# static fields
.field private static final EXIT_URL_RESULT_CODE_PARAM_KEY:Ljava/lang/String; = "status"

.field private static final EXIT_URL_TARGET_URL_PARAM_KEY:Ljava/lang/String; = "url"

.field public static final LOG_TAG:Ljava/lang/String; = "OfferWebClient"

.field public static final RESULT_CODE_NO_STATUS_CODE:I = -0xa

.field private static final SPONSORPAY_EXIT_SCHEMA:Ljava/lang/String; = "exit"

.field private static final SPONSORPAY_SCHEMA:Ljava/lang/String; = "sponsorpay://"


# instance fields
.field private mHostActivityRef:Ljava/lang/ref/WeakReference;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/lang/ref/WeakReference",
            "<",
            "Landroid/app/Activity;",
            ">;"
        }
    .end annotation
.end field


# direct methods
.method public constructor <init>(Landroid/app/Activity;)V
    .locals 1
    .parameter "hostActivity"

    .prologue
    .line 48
    invoke-direct {p0}, Landroid/webkit/WebViewClient;-><init>()V

    .line 49
    new-instance v0, Ljava/lang/ref/WeakReference;

    invoke-direct {v0, p1}, Ljava/lang/ref/WeakReference;-><init>(Ljava/lang/Object;)V

    iput-object v0, p0, Lcom/sponsorpay/sdk/android/publisher/OfferWebClient;->mHostActivityRef:Ljava/lang/ref/WeakReference;

    .line 50
    return-void
.end method


# virtual methods
.method protected getHostActivity()Landroid/app/Activity;
    .locals 1

    .prologue
    .line 53
    iget-object v0, p0, Lcom/sponsorpay/sdk/android/publisher/OfferWebClient;->mHostActivityRef:Ljava/lang/ref/WeakReference;

    invoke-virtual {v0}, Ljava/lang/ref/WeakReference;->get()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Landroid/app/Activity;

    return-object v0
.end method

.method protected launchActivityWithUrl(Ljava/lang/String;)Z
    .locals 8
    .parameter "url"

    .prologue
    const/4 v4, 0x0

    .line 114
    invoke-virtual {p0}, Lcom/sponsorpay/sdk/android/publisher/OfferWebClient;->getHostActivity()Landroid/app/Activity;

    move-result-object v1

    .line 115
    .local v1, hostActivity:Landroid/app/Activity;
    if-nez v1, :cond_1

    .line 140
    :cond_0
    :goto_0
    return v4

    .line 118
    :cond_1
    if-eqz p1, :cond_0

    .line 122
    new-instance v2, Landroid/content/Intent;

    invoke-direct {v2}, Landroid/content/Intent;-><init>()V

    .line 123
    .local v2, intent:Landroid/content/Intent;
    const-string v5, "android.intent.action.VIEW"

    invoke-virtual {v2, v5}, Landroid/content/Intent;->setAction(Ljava/lang/String;)Landroid/content/Intent;

    .line 124
    invoke-static {p1}, Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;

    move-result-object v3

    .line 125
    .local v3, uri:Landroid/net/Uri;
    invoke-virtual {v2, v3}, Landroid/content/Intent;->setData(Landroid/net/Uri;)Landroid/content/Intent;

    .line 127
    :try_start_0
    invoke-virtual {v1, v2}, Landroid/app/Activity;->startActivity(Landroid/content/Intent;)V

    .line 128
    invoke-virtual {p0, p1}, Lcom/sponsorpay/sdk/android/publisher/OfferWebClient;->onTargetActivityStart(Ljava/lang/String;)V
    :try_end_0
    .catch Landroid/content/ActivityNotFoundException; {:try_start_0 .. :try_end_0} :catch_0

    .line 140
    const/4 v4, 0x1

    goto :goto_0

    .line 129
    :catch_0
    move-exception v0

    .line 130
    .local v0, e:Landroid/content/ActivityNotFoundException;
    invoke-virtual {v3}, Landroid/net/Uri;->getScheme()Ljava/lang/String;

    move-result-object v5

    const-string v6, "market"

    invoke-virtual {v5, v6}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v5

    if-eqz v5, :cond_0

    invoke-virtual {p0}, Lcom/sponsorpay/sdk/android/publisher/OfferWebClient;->getHostActivity()Landroid/app/Activity;

    move-result-object v5

    .line 131
    const-string v6, "android.intent.action.VIEW"

    .line 133
    const-string v7, "market://search?q=pname:com.google"

    invoke-static {v7}, Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;

    move-result-object v7

    .line 130
    invoke-static {v5, v6, v7}, Lcom/sponsorpay/sdk/android/utils/IntentHelper;->isIntentAvailable(Landroid/content/Context;Ljava/lang/String;Landroid/net/Uri;)Z

    move-result v5

    .line 133
    if-nez v5, :cond_0

    .line 134
    const-string v5, "OfferWebClient"

    const-string v6, "Play Store is not installed on this device..."

    invoke-static {v5, v6}, Lcom/sponsorpay/sdk/android/utils/SponsorPayLogger;->e(Ljava/lang/String;Ljava/lang/String;)V

    .line 135
    invoke-virtual {p0}, Lcom/sponsorpay/sdk/android/publisher/OfferWebClient;->onPlayStoreNotFound()V

    goto :goto_0
.end method

.method protected onPlayStoreNotFound()V
    .locals 1

    .prologue
    .line 150
    sget-object v0, Lcom/sponsorpay/sdk/android/publisher/SponsorPayPublisher$UIStringIdentifier;->ERROR_PLAY_STORE_UNAVAILABLE:Lcom/sponsorpay/sdk/android/publisher/SponsorPayPublisher$UIStringIdentifier;

    invoke-static {v0}, Lcom/sponsorpay/sdk/android/publisher/SponsorPayPublisher;->getUIString(Lcom/sponsorpay/sdk/android/publisher/SponsorPayPublisher$UIStringIdentifier;)Ljava/lang/String;

    move-result-object v0

    invoke-virtual {p0, v0}, Lcom/sponsorpay/sdk/android/publisher/OfferWebClient;->showDialog(Ljava/lang/String;)V

    .line 151
    return-void
.end method

.method public onReceivedSslError(Landroid/webkit/WebView;Landroid/webkit/SslErrorHandler;Landroid/net/http/SslError;)V
    .locals 2
    .parameter "view"
    .parameter "handler"
    .parameter "error"

    .prologue
    .line 182
    invoke-virtual {p3}, Landroid/net/http/SslError;->getCertificate()Landroid/net/http/SslCertificate;

    move-result-object v0

    invoke-virtual {v0}, Landroid/net/http/SslCertificate;->getIssuedBy()Landroid/net/http/SslCertificate$DName;

    move-result-object v0

    invoke-virtual {v0}, Landroid/net/http/SslCertificate$DName;->getOName()Ljava/lang/String;

    move-result-object v0

    .line 183
    const-string v1, ".*StartCom Ltd.*"

    invoke-virtual {v0, v1}, Ljava/lang/String;->matches(Ljava/lang/String;)Z

    move-result v0

    if-eqz v0, :cond_0

    .line 184
    invoke-virtual {p2}, Landroid/webkit/SslErrorHandler;->proceed()V

    .line 186
    :cond_0
    return-void
.end method

.method protected abstract onSponsorPayExitScheme(ILjava/lang/String;)V
.end method

.method protected abstract onTargetActivityStart(Ljava/lang/String;)V
.end method

.method protected parseSponsorPayExitUrlForResultCode(Ljava/lang/String;)I
    .locals 3
    .parameter "url"

    .prologue
    .line 77
    invoke-static {p1}, Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;

    move-result-object v1

    .line 79
    .local v1, uri:Landroid/net/Uri;
    const-string v2, "status"

    invoke-virtual {v1, v2}, Landroid/net/Uri;->getQueryParameter(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    .line 81
    .local v0, resultCodeAsString:Ljava/lang/String;
    if-eqz v0, :cond_0

    .line 82
    invoke-static {v0}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;)I

    move-result v2

    .line 84
    :goto_0
    return v2

    :cond_0
    const/16 v2, -0xa

    goto :goto_0
.end method

.method protected parseSponsorPayExitUrlForTargetUrl(Ljava/lang/String;)Ljava/lang/String;
    .locals 2
    .parameter "url"

    .prologue
    .line 64
    invoke-static {p1}, Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;

    move-result-object v0

    .line 66
    .local v0, uri:Landroid/net/Uri;
    const-string v1, "url"

    invoke-virtual {v0, v1}, Landroid/net/Uri;->getQueryParameter(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1

    return-object v1
.end method

.method protected abstract processSponsorPayScheme(Ljava/lang/String;Landroid/net/Uri;)V
.end method

.method public shouldOverrideUrlLoading(Landroid/webkit/WebView;Ljava/lang/String;)Z
    .locals 7
    .parameter "view"
    .parameter "url"

    .prologue
    .line 89
    const-string v4, "OfferWebClient"

    new-instance v5, Ljava/lang/StringBuilder;

    const-string v6, "shouldOverrideUrlLoading called with url: "

    invoke-direct {v5, v6}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v5, p2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v5

    invoke-virtual {v5}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v5

    invoke-static {v4, v5}, Lcom/sponsorpay/sdk/android/utils/SponsorPayLogger;->i(Ljava/lang/String;Ljava/lang/String;)V

    .line 91
    const-string v4, "sponsorpay://"

    invoke-virtual {p2, v4}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z

    move-result v4

    if-eqz v4, :cond_1

    .line 92
    invoke-static {p2}, Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;

    move-result-object v3

    .line 93
    .local v3, uri:Landroid/net/Uri;
    invoke-virtual {v3}, Landroid/net/Uri;->getHost()Ljava/lang/String;

    move-result-object v0

    .line 94
    .local v0, host:Ljava/lang/String;
    const-string v4, "exit"

    invoke-virtual {v0, v4}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v4

    if-eqz v4, :cond_0

    .line 96
    invoke-virtual {p0, p2}, Lcom/sponsorpay/sdk/android/publisher/OfferWebClient;->parseSponsorPayExitUrlForResultCode(Ljava/lang/String;)I

    move-result v1

    .line 97
    .local v1, resultCode:I
    invoke-virtual {p0, p2}, Lcom/sponsorpay/sdk/android/publisher/OfferWebClient;->parseSponsorPayExitUrlForTargetUrl(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v2

    .line 99
    .local v2, targetUrl:Ljava/lang/String;
    const-string v4, "OfferWebClient"

    new-instance v5, Ljava/lang/StringBuilder;

    const-string v6, "Overriding. Target Url: "

    invoke-direct {v5, v6}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v5, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v5

    invoke-virtual {v5}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v5

    invoke-static {v4, v5}, Lcom/sponsorpay/sdk/android/utils/SponsorPayLogger;->i(Ljava/lang/String;Ljava/lang/String;)V

    .line 101
    invoke-virtual {p0, v1, v2}, Lcom/sponsorpay/sdk/android/publisher/OfferWebClient;->onSponsorPayExitScheme(ILjava/lang/String;)V

    .line 106
    .end local v1           #resultCode:I
    .end local v2           #targetUrl:Ljava/lang/String;
    :goto_0
    const/4 v4, 0x1

    .line 109
    .end local v0           #host:Ljava/lang/String;
    .end local v3           #uri:Landroid/net/Uri;
    :goto_1
    return v4

    .line 103
    .restart local v0       #host:Ljava/lang/String;
    .restart local v3       #uri:Landroid/net/Uri;
    :cond_0
    invoke-virtual {p0, v0, v3}, Lcom/sponsorpay/sdk/android/publisher/OfferWebClient;->processSponsorPayScheme(Ljava/lang/String;Landroid/net/Uri;)V

    goto :goto_0

    .line 108
    .end local v0           #host:Ljava/lang/String;
    .end local v3           #uri:Landroid/net/Uri;
    :cond_1
    const-string v4, "OfferWebClient"

    const-string v5, "Not overriding"

    invoke-static {v4, v5}, Lcom/sponsorpay/sdk/android/utils/SponsorPayLogger;->i(Ljava/lang/String;Ljava/lang/String;)V

    .line 109
    const/4 v4, 0x0

    goto :goto_1
.end method

.method public showDialog(Ljava/lang/String;)V
    .locals 8
    .parameter "errorMessage"

    .prologue
    .line 155
    sget-object v5, Lcom/sponsorpay/sdk/android/publisher/SponsorPayPublisher$UIStringIdentifier;->ERROR_DIALOG_TITLE:Lcom/sponsorpay/sdk/android/publisher/SponsorPayPublisher$UIStringIdentifier;

    invoke-static {v5}, Lcom/sponsorpay/sdk/android/publisher/SponsorPayPublisher;->getUIString(Lcom/sponsorpay/sdk/android/publisher/SponsorPayPublisher$UIStringIdentifier;)Ljava/lang/String;

    move-result-object v4

    .line 157
    .local v4, errorDialogTitle:Ljava/lang/String;
    sget-object v5, Lcom/sponsorpay/sdk/android/publisher/SponsorPayPublisher$UIStringIdentifier;->DISMISS_ERROR_DIALOG:Lcom/sponsorpay/sdk/android/publisher/SponsorPayPublisher$UIStringIdentifier;

    invoke-static {v5}, Lcom/sponsorpay/sdk/android/publisher/SponsorPayPublisher;->getUIString(Lcom/sponsorpay/sdk/android/publisher/SponsorPayPublisher$UIStringIdentifier;)Ljava/lang/String;

    move-result-object v2

    .line 159
    .local v2, dismissButtonCaption:Ljava/lang/String;
    new-instance v1, Landroid/app/AlertDialog$Builder;

    invoke-virtual {p0}, Lcom/sponsorpay/sdk/android/publisher/OfferWebClient;->getHostActivity()Landroid/app/Activity;

    move-result-object v5

    invoke-direct {v1, v5}, Landroid/app/AlertDialog$Builder;-><init>(Landroid/content/Context;)V

    .line 160
    .local v1, dialogBuilder:Landroid/app/AlertDialog$Builder;
    invoke-virtual {v1, v4}, Landroid/app/AlertDialog$Builder;->setTitle(Ljava/lang/CharSequence;)Landroid/app/AlertDialog$Builder;

    .line 161
    invoke-virtual {v1, p1}, Landroid/app/AlertDialog$Builder;->setMessage(Ljava/lang/CharSequence;)Landroid/app/AlertDialog$Builder;

    .line 162
    new-instance v5, Lcom/sponsorpay/sdk/android/publisher/OfferWebClient$1;

    invoke-direct {v5, p0}, Lcom/sponsorpay/sdk/android/publisher/OfferWebClient$1;-><init>(Lcom/sponsorpay/sdk/android/publisher/OfferWebClient;)V

    invoke-virtual {v1, v2, v5}, Landroid/app/AlertDialog$Builder;->setNegativeButton(Ljava/lang/CharSequence;Landroid/content/DialogInterface$OnClickListener;)Landroid/app/AlertDialog$Builder;

    .line 168
    invoke-virtual {v1}, Landroid/app/AlertDialog$Builder;->create()Landroid/app/AlertDialog;

    move-result-object v0

    .line 169
    .local v0, dialog:Landroid/app/AlertDialog;
    invoke-virtual {p0}, Lcom/sponsorpay/sdk/android/publisher/OfferWebClient;->getHostActivity()Landroid/app/Activity;

    move-result-object v5

    invoke-virtual {v0, v5}, Landroid/app/AlertDialog;->setOwnerActivity(Landroid/app/Activity;)V

    .line 171
    :try_start_0
    invoke-virtual {v0}, Landroid/app/AlertDialog;->show()V
    :try_end_0
    .catch Landroid/view/WindowManager$BadTokenException; {:try_start_0 .. :try_end_0} :catch_0

    .line 177
    :goto_0
    return-void

    .line 172
    :catch_0
    move-exception v3

    .line 173
    .local v3, e:Landroid/view/WindowManager$BadTokenException;
    invoke-virtual {p0}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v5

    invoke-virtual {v5}, Ljava/lang/Class;->getSimpleName()Ljava/lang/String;

    move-result-object v5

    .line 174
    new-instance v6, Ljava/lang/StringBuilder;

    const-string v7, "Couldn\'t show error dialog. Not displayed error message is: "

    invoke-direct {v6, v7}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v6, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v6

    .line 173
    invoke-static {v5, v6, v3}, Lcom/sponsorpay/sdk/android/utils/SponsorPayLogger;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Exception;)V

    goto :goto_0
.end method
